import { createStore } from 'vuex';
import { LocalStorage } from '../utils/storage';

const store = createStore({
  state: {
    token: LocalStorage.getItem('token') || null,
    userInfo: JSON.parse(LocalStorage.getItem('userInfo') || '{}')
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
      LocalStorage.setItem('token', token);
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
      LocalStorage.setItem('userInfo', JSON.stringify(userInfo));
    }
  },
  actions: {},
  getters: {}
});

export default store;